Homework 8

Total points: 100
Topics: methods (write several methods; reuse written methods to help you achieve new tasks - see recommended use of add queen to implement delete queen-), 2D arrays (traversal, formatted printing), loop with menu, drawing data, split method, 'distribute' data from one array to other arrays.


Task 1 (15 pts)

Project: HW8_RobotSanta
Objectives: review split to build array from string, write code for problem discussed in class for problem solving, 'distribute' data from one array to other arrays.

Write the program for this Robot Santa problem. Assume that each present is given by a name consisting of a label (A for Alice or B for Bob) and a toy name. For example "A doll" means it is a doll and it should go to Alice (A), "B train set" means it is a train set and will go to Bob (B).
The presents are given by the user as a list separated by ;.
a) Write a program that reads the list from the user and creates 2 arrays with the presents for Alice and Bob with just the toy name, not the label. See sample run below.
You must create two arrays (AliceArr and BobArr) and store the presents for Alice in AliceArr and the presents for Bob in BobArr.
Hint: Use the split method to quickly turn the string of labelled presents into a 1D array of strings
 ----------Sample run:
 Enter the presents:A doll;B train set;B drawing pad;A car;A Teddy bear;A puzzle;A pen
 
 Alice gets:
 doll
 car
 Teddy bear
 puzzle
 pen
 
 Bob gets:
 train set
 drawing pad
 
EXTEND YOUR THINKING (this part will not be graded): A method can only return one 'thing' in Java (e.g. an int, String, array,...). How would you "put together" AliceArr and BobArr into one 2D array that you could then return from a method?

Task 2a (75 pts)

Project: HW8_PlaceQueens
Objectives: writing a complex program that includes: updating and printing a 2D table (printed table will have labelled rows and columns), error checking. Practice modularization by having to structure the program using methods (reuse written methods to help you achieve new tasks - see recommended use of add queen to implement delete queen-).

This program will maintain and print a chessboard that allows the user to place Queen pieces. The board will show the Queens and the row, column and diagonals the Queens will attack on.
Implement the behaviour shown in the sample run below.
Code structure (a method to do the work for each user option): Other specifications: See sample runs: Suggested: start with the menu,argument passing and error checking and you slowly add the functionality. Use method stubs (i.e. a placeholder, or a "dummy" method that matches the signature needed). Ask in class if you want to discuss method stubs further.

Task 2b - Written part (10 points)

Submit the answers for this part in a document called HW8_written.pdf. It must be an electronic document of type pdf, but it can be a scan or photo of a handwritten paper.

Part b (10 points)
Draw the data for the delete queen method that is called FIRST in the delete.txt sample run. (You have the 3 queens that were added and need to delete the queen at row 5 row 3 and column 1.) Show the code on the left side and the drawing on the right side for each main step. A 'main step is: a method call, a complete execution of loop, one iteration of the OUTTER loop in nested loops.

Penalties

All solution files should be placed in a folder called HW8_Lastname. Zip this folder and submit it to Blackboard.
  1. The submitted homework must use methods as required.
  2. CODE THAT DOES NOT RUN due to a SYNTAX ERROR 25%-80% penalty per task. Notice that this penalty is up to 80% now. At this point I expect you are able to understand the syntax and fix such problems.
  3. RUN-TIME ERROR FOR INPUT SPECIFICALLY SHOWED AS AN EXAMPLE: 20% of task grade. Runtime-error for grader’s input: 5-20% of task grade (depending on the reason of why it fails).
  4. **** Code using elements we had not covered at the time the homework was due, receives no credit.
  5. Up to 20 points will be lost for non-compliance with the submission requirements: folder name, all files in a folder, zipped folder, the compressed file is a zip, the program files have extension .java, ...
  6. Each program must have: A program missing some or all of these will receive a penalty of up to 10% of the points for that task.